//
//  PACardAuthView.m
//  PAMobileWallet
//
//  Created by Pay_SMP002 on 13-7-4.
//  Copyright (c) 2013年 平安付. All rights reserved.
//

#import "PACardAuthView.h"
#import "UIColor+Extend.h"
#import "PABaseViewController.h"
#import "UIColor+Extend.h"

@implementation PACardAuthView

@synthesize view_one;
@synthesize viewoneBgImage;
@synthesize markImage;
@synthesize bankNameLable;
@synthesize bankNumLable;

@synthesize view_three;
@synthesize chekTFBgImage;
@synthesize chekTF;

@synthesize view_four;
@synthesize cardNumTFImage;
@synthesize cardNumTF;
@synthesize checkButton;

@synthesize view_five;
@synthesize agreeButton;
@synthesize readButton;

@synthesize nextButton;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self){
        //title one
        view_one = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 50)];
        view_one.backgroundColor = [UIColor clearColor];
        
        viewoneBgImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 290, 50)];
        viewoneBgImage.image = [UIImage imageNamed:@"textbox2.png"];
        [view_one addSubview:viewoneBgImage];
        
        markImage = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15/2, 100, 70/2)];
        markImage.image = [UIImage imageNamed:@""];
        [view_one addSubview:markImage];
        
        // 卡的类型
        bankNameLable = [[UILabel alloc] initWithFrame:CGRectMake(5+100+15+120, 0, 50, 50)];
        //bankNameLable.text = @"平安银行";
        bankNameLable.backgroundColor = [UIColor clearColor];
        bankNameLable.textColor = CARDTYPE_COLOR;
        bankNameLable.font = [UIFont boldSystemFontOfSize:15.0];
        [view_one addSubview:bankNameLable];
        
        bankNumLable = [[UILabel alloc] initWithFrame:CGRectMake(5+100+15+20, 0, 120, 50)];
        //bankNumLable.text = @"尾号为6625的储蓄卡";
        bankNumLable.backgroundColor = [UIColor clearColor];
        bankNumLable.textColor = ENABLE_COLOR;
        bankNumLable.font = [UIFont boldSystemFontOfSize:16.0];
        bankNumLable.textColor = [UIColor grayColor];
        [view_one addSubview:bankNumLable];
        
        //title three
        view_three = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 50)];
        view_three.backgroundColor = [UIColor clearColor];
        
        chekTFBgImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 290, 50)];
        chekTFBgImage.image = [UIImage imageNamed:@"textbox.png"];
        chekTFBgImage.backgroundColor = [UIColor clearColor];
        [view_three addSubview:chekTFBgImage];
        
        chekTF = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, 290, 50)];
        [chekTF setBorderStyle:UITextBorderStyleNone]; //外框类型
        chekTF.keyboardType = UIKeyboardTypeNumberPad;
        chekTF.placeholder = @"此卡在银行预留手机号"; //默认显示的字
        chekTF.secureTextEntry = NO; //密码
        chekTF.delegate = self;
        chekTF.tag = 40;
        chekTF.contentHorizontalAlignment = NSTextAlignmentCenter;
        chekTF.contentVerticalAlignment = NSTextAlignmentLeft;
        chekTF.backgroundColor = [UIColor clearColor];
        chekTF.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
        [chekTF setBackgroundColor:[UIColor clearColor]];
        [view_three addSubview:chekTF];
        
        //title four
        view_four = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 50)];
        view_four.backgroundColor = [UIColor clearColor];
        
        cardNumTFImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0,290, 50)];
        cardNumTFImage.image = [UIImage imageNamed:@"textbox.png"];
        cardNumTFImage.backgroundColor = [UIColor clearColor];
        [view_four addSubview:cardNumTFImage];

        cardNumTF = [[UITextField alloc] initWithFrame:CGRectMake(20, 0,300-10-80-10-30, 50)];
        [cardNumTF setBorderStyle:UITextBorderStyleNone]; //外框类型
        cardNumTF.keyboardType = UIKeyboardTypeNumberPad;
        cardNumTF.placeholder = @"短信验证码"; //默认显示的字
        cardNumTF.secureTextEntry = NO; //密码
        cardNumTF.delegate = self;
        cardNumTF.tag = 30;
        cardNumTF.contentHorizontalAlignment = NSTextAlignmentCenter;
        cardNumTF.contentVerticalAlignment = NSTextAlignmentLeft;
        cardNumTF.backgroundColor = [UIColor clearColor];
        cardNumTF.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
        [chekTF setBackgroundColor:[UIColor clearColor]];
        [view_four addSubview:cardNumTF];
        
        //  验证码
        checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
        checkButton.frame = CGRectMake(300-110-2,14/2, 110, 38);
        checkButton.backgroundColor = [UIColor clearColor];
        [checkButton setTitle:@"获取验证码" forState:UIControlStateNormal];
        [checkButton setBackgroundImage:[UIImage imageNamed:@"card_check4.png"] forState:UIControlStateNormal];
        [checkButton setTintColor:ENABLE_COLOR];
        checkButton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
        [checkButton addTarget:self action:@selector(changeState:) forControlEvents:UIControlEventTouchUpInside];
        checkButton.enabled = NO;
        checkButton.tag = 10;
        [view_four addSubview:checkButton];
        
        //title five
        view_five = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 40)];
        view_five.backgroundColor = [UIColor clearColor];
        
        UIImageView * lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, 8/2, 310, 1)];
        lineImage.image = [UIImage imageNamed:@"register_line.png"];
        lineImage.backgroundColor = [UIColor clearColor];
        [view_five addSubview:lineImage];
        
        //  是否同意按钮
        agreeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        agreeButton.frame = CGRectMake(10, 13, 24, 24);
        [agreeButton addTarget:self action:@selector(changeState:) forControlEvents:UIControlEventTouchUpInside];
        [agreeButton setBackgroundImage:[UIImage imageNamed:@"register_seclectYES.png"] forState:UIControlStateNormal];
        agreeButton.selected = NO;
        agreeButton.tag = 20;
        [view_five addSubview:agreeButton];
        
        UILabel * agreeLable = [[UILabel alloc] initWithFrame:CGRectMake(10+24+5,13, 100, 24)];
        agreeLable.textColor = [UIColor grayColor];
        agreeLable.text = @"同意协议";
        agreeLable.font = [UIFont systemFontOfSize:16.0];
        [view_five addSubview:agreeLable];
        
        //  阅读条款按钮
        readButton = [UIButton buttonWithType:UIButtonTypeCustom];
        readButton.frame = CGRectMake(300-180+8, 13, 190, 24);
        [readButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
        readButton.titleLabel.font = [UIFont systemFontOfSize:16.0];
        readButton.titleLabel.textAlignment = NSTextAlignmentRight;
        [readButton setTitle:@"转账宝快捷支付协议" forState:UIControlStateNormal];
        [readButton setTitleColor:[UIColor colorWithHexString:@"3999D0"] forState:UIControlStateNormal];
        readButton.tag = 30;
        [readButton setBackgroundColor:[UIColor clearColor]];
        [view_five addSubview:readButton];
        
        //title six   下一步按钮
        nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
        nextButton.frame = CGRectMake(300-24-80, 0, 80, 100/2);
        [nextButton addTarget:self action:@selector(buttonActive:) forControlEvents:UIControlEventTouchUpInside];
        [nextButton setBackgroundImage:[UIImage imageNamed:@"card_next1.png"] forState:UIControlStateDisabled];
        [nextButton setTitleColor:ENABLE_COLOR forState:UIControlStateDisabled];
        
        nextButton.titleLabel.textColor = ENABLE_COLOR;
        nextButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
        nextButton.enabled = NO;
        nextButton.tag = 40;
        [nextButton setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
    }
    return self;
}

- (void)changeState:(UIButton *)sender
{
    if (sender == self.agreeButton)
    {
        if (!self.agreeButton.selected)
        {
            [agreeButton setBackgroundImage:[UIImage imageNamed:@"register_seclectNO.png"] forState:UIControlStateNormal];
            self.agreeButton.selected = YES;
            
            [nextButton setBackgroundImage:[UIImage imageNamed:@"card_next1.png"] forState:UIControlStateDisabled];            
            [nextButton setTitleColor:ENABLE_COLOR forState:UIControlStateDisabled];
            
            nextButton.enabled = NO;
        }
        else
        {
            [agreeButton setBackgroundImage:[UIImage imageNamed:@"register_seclectYES.png"] forState:UIControlStateNormal];
            self.agreeButton.selected = NO;
            
            if ([cardNumTF.text length] == 6) {
                [nextButton setBackgroundImage:[UIImage imageNamed:@"card_next.png"] forState:UIControlStateNormal];
                nextButton.enabled = YES;
            }
            else{
                [nextButton setBackgroundImage:[UIImage imageNamed:@"card_next1.png"] forState:UIControlStateDisabled];
                [nextButton setTitleColor:ENABLE_COLOR forState:UIControlStateDisabled];
                nextButton.enabled = NO;
            }
        }
    }
    else if (sender == checkButton)
    {
        if (self.parentController && [self.parentController respondsToSelector:@selector(checkMessage:)])
        {
            [self.parentController performSelector:@selector(checkMessage:) withObject:sender];
        }
    }
}

-(void)buttonActive:(id)sender
{
    [self.parentController testNext:sender];
}

@end
